﻿Imports System.ExecutorServices
Imports System.Runtime.CompilerServices
Imports System.Aspect

Namespace Data.Objects

    Public Module Customer

        <Item("Customer", "customer")> Public Interface ICustomer
            <Field("CustomerID", "customer id")> Property CustomerID() As Integer
        End Interface

        Public Interface ICustomerInfo
            Inherits ICustomer
            <Field("CustomerName", "customer name")> Property CustomerName() As String
        End Interface

        <Extension()> _
        Public Function AddSalesOrder(ByVal c As ICustomer, ByVal OrderDate As DateTime) As ISalesOrderInfo
            Return SalesOrder.AddSalesOrder(c, OrderDate)
        End Function

        Public GetNew As dcGetNew = Aspect(Of dcGetNew)()
        <DataCall("AddANewCustomer", "add a new customer")> Public Delegate Function dcGetNew( _
        <Field("CustomerName", "customer name")> ByVal CustomerName As String) As ICustomerInfo

        Public GetAll As dcGetAll = Aspect(Of dcGetAll)()
        <DataCall("GetAllCustomers", "get all customers")> Public Delegate Function dcGetAll() As ICustomerInfo()

        <Extension()> _
        Public Sub DeleteThisCustomer(ByVal c As ICustomer)
            _dataCallDeleteCustomer(c.CustomerID)
        End Sub

        <DataCall("DeleteCustomer", "delete a customer")> Private Delegate Sub dcDeleteCustomer( _
        <Field("CustomerID", "customer id")> ByVal CustomerID As Integer)
        Private _dataCallDeleteCustomer As dcDeleteCustomer = Aspect(Of dcDeleteCustomer)()

    End Module

End Namespace